package leetcode.d1;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: hang an
 * @Date: 2025/5/16
 * @Description:
 */
public class R3527 {
    public String findCommonResponse(List<List<String>> responses) {
        HashMap<String, Integer> cnt = new HashMap<>();
        for (List<String> respons : responses) {
            HashSet<String> set = new HashSet<>(respons);
            for (String s : set) {
                cnt.put(s, cnt.getOrDefault(s, 0) + 1);
            }
        }
        String ans = "";
        int c = 0;
        Set<Map.Entry<String, Integer>> entries = cnt.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            if (value > c) {
                c = value;
                ans = key;
            } else if (value == c && key.compareTo(ans) < 0) {
                ans = key;
            }
        }
        return ans;

    }
}
